import request from '@/utils/request'

// 服务器大区
export function getServerRegionList() {
  return request({
    url: '/server/region/list',
    method: 'get'
  })
}

export function getVersionList() {
  return request({
    url: '/server/channel/version/list',
    method: 'get'
  })
}

export function handleServerRegion(data) {
  return request({
    url: '/server/region/handle',
    method: 'post',
    data
  })
}

export function getCrossServerConfigNum() {
  return request({
    url: '/server/region/configNum',
    method: 'get'
  })
}

export function handleConfigNum(data) {
  return request({
    url: '/server/region/handleConfigNum',
    method: 'post',
    data
  })
}

export function crossServerGroupList(query) {
  return request({
    url: '/server/crossServer/group/list',
    method: 'get',
    params: query
  })
}
export function crossServerGroupTypeList(query) {
  return request({
    url: '/server/crossServer/group/typeList',
    method: 'get',
    params: query
  })
}
export function handleCrossServerParam(data) {
  return request({
    url: '/server/crossServer/group/handle',
    method: 'post',
    data
  })
}
export function crossServerServerList(query) {
  return request({
    url: '/server/crossServer/group/serverList',
    method: 'get',
    params: query
  })
}
export function handleServerStrategy(data) {
  return request({
    url: '/server/strategy/handle',
    method: 'post',
    data
  })
}

export function handleCrossServer(data) {
  return request({
    url: '/server/region/cross/handle',
    method: 'post',
    data
  })
}

export function handleChat(data) {
  return request({
    url: '/server/region/chat',
    method: 'post',
    data
  })
}

export function deleteServerRegion(id) {
  return request({
    url: `/server/region/delete/${id}`,
    method: 'delete'
  })
}

export function handleSwithBattle(id, status) {
  return request({
    url: `/server/region/handle/${id}/${status}`,
    method: 'patch'
  })
}

// 服务器分组
export function getServerGroupList() {
  return request({
    url: '/server/group/list',
    method: 'get'
  })
}

export function handleServerGroup(data) {
  return request({
    url: '/server/group/handle',
    method: 'post',
    data
  })
}

export function deleteServerGroup(id) {
  return request({
    url: `/server/group/delete/${id}`,
    method: 'delete'
  })
}

// 渠道管理
export function getChannelList(query) {
  return request({
    url: '/channel/list/',
    method: 'get',
    params: query
  })
}

export function getAllChannel(query) {
  return request({
    url: '/channel/all',
    method: 'get'
  })
}

export function getAllChannelList(query) {
  return request({
    url: '/channel/group/all',
    method: 'get'
  })
}

export function getSDKList(query) {
  return request({
    url: '/channel/sdk/list',
    method: 'get'
  })
}

export function getChannelGroupConfigList(query) {
  return request({
    url: '/channel/group/config',
    method: 'get'
  })
}

export function getAllSortsChannel() {
  return request({
    url: '/channel/all/sorts',
    method: 'get'
  })
}

export function handleChannel(data) {
  return request({
    url: '/channel/handle',
    method: 'post',
    data
  })
}

// 渠道包管理
export function getChannelPackageList(query) {
  return request({
    url: '/channelpackage/list/',
    method: 'get',
    params: query
  })
}

export function handleChannelPackage(data) {
  return request({
    url: '/channelpackage/handle',
    method: 'post',
    data
  })
}

export function handleInfo(data) {
  return request({
    url: '/channelpackage/info',
    method: 'post',
    data
  })
}

export function getChannelPackageDefaultContent(query) {
  return request({
    url: '/channelpackage/default',
    method: 'get',
    params: query
  })
}

export function deleteChannelPackage(id) {
  return request({
    url: `/channelpackage/delete/${id}`,
    method: 'delete'
  })
}

export function getChannelPackageListGroup(val) {
  return request({
    url: '/channelpackage/group/list',
    method: 'get',
    params: val
  })
}

// IOS审核包
export function getIosPackageList(query) {
  return request({
    url: '/iospackage/list/',
    method: 'get',
    params: query
  })
}

export function handleIosPackage(data) {
  return request({
    url: '/iospackage/handle',
    method: 'post',
    data
  })
}

export function deleteIosPackage(id) {
  return request({
    url: `/iospackage/delete/${id}`,
    method: 'delete'
  })
}

// 服务器管理
export function getServerList(query) {
  return request({
    url: '/server/list/',
    method: 'get',
    params: { data_type: 'all', ...query }
  })
}

export function getServerQuery(query) {
  return request({
    url: '/server/query/',
    method: 'get',
    params: query
  })
}

export function handleServer(data) {
  return request({
    url: '/server/handle',
    method: 'post',
    data
  })
}

export function batchModifyServerGroup(data) {
  return request({
    url: '/server/modifyServerGroup',
    method: 'post',
    data
  })
}

export function batchAddServer(data) {
  return request({
    url: '/server/batchAddServer',
    method: 'post',
    data
  })
}

export function batchModifyRecommend(data) {
  return request({
    url: '/server/batchModifyRecommend',
    method: 'post',
    data
  })
}

export function batchModifyStatus(data) {
  return request({
    url: '/server/batchModifyStatus',
    method: 'post',
    data
  })
}

export function deleteServer(id) {
  return request({
    url: `/server/delete/${id}`,
    method: 'delete'
  })
}

export function kickPlayerOut(data) {
  return request({
    url: `/server/kickout`,
    method: 'post',
    data
  })
}

export function getServerByDays(query) {
  return request({
    url: '/server/days/group/list',
    method: 'get',
    params: query
  })
}

// 白名单
export function getWhitelist(query) {
  return request({
    url: '/whitelist/list',
    method: 'get',
    params: query
  })
}

export function handleWhitelist(data) {
  return request({
    url: '/whitelist/handle',
    method: 'post',
    data
  })
}

export function deleteWhitelist(id) {
  return request({
    url: `/whitelist/delete/${id}`,
    method: 'delete'
  })
}

export function batchDeleteWhitelist(ids) {
  return request({
    url: `/whitelist/batchDelete`,
    method: 'post',
    params: ids
  })
}

export function getServerListGroup(val) {
  return request({
    url: '/server/group/list',
    method: 'post',
    params: val
  })
}

// 设备码
export function getDeviceList(query) {
  return request({
    url: '/device/list',
    method: 'get',
    params: query
  })
}

export function deleteDeviceCode(id) {
  return request({
    url: `/device/delete/${id}`,
    method: 'delete'
  })
}

export function handleDevice(data) {
  return request({
    url: '/device/handle',
    method: 'post',
    data
  })
}

export function batchDeleteDevice(ids) {
  return request({
    url: `/device/batchDelete`,
    method: 'post',
    params: ids
  })
}

export function handleSwithDevice(status) {
  return request({
    url: `/device/handle/${status}`,
    method: 'patch'
  })
}

export function getOperateLogList(query) {
  return request({
    url: '/operator/log/list',
    method: 'get',
    params: query
  })
}

export function handleSql(formData, customHeaders = {}) {
  // 创建 FormData 对象
  const form = new FormData()

  // 遍历 formData，将所有字段添加到 FormData 中
  for (const key in formData) {
    if (formData[key] !== null && formData[key] !== undefined) {
      form.append(key, formData[key])
    }
  }

  return request({
    url: '/operator/sql/handleSql',
    method: 'post',
    data: form, // 使用 FormData 对象作为请求体
    headers: {
      'Content-Type': 'multipart/form-data', // 设置 Content-Type
      ...customHeaders // 动态合并自定义请求头
    }
  })
}

export function historySql(query) {
  return request({
    url: '/operator/sql/list',
    method: 'get',
    params: query
  })
}

